package com.oa.notice.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.oa.common.utils.DateUtils;
import com.oa.common.utils.SecurityUtils;
import com.oa.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.oa.notice.mapper.OaNoticeMapper;
import com.oa.notice.domain.OaNotice;
import com.oa.notice.service.IOaNoticeService;

/**
 * 通知公告Service业务层处理
 * 
 * @author li.ziye
 * @date 2022-05-11
 */
@Service
public class OaNoticeServiceImpl implements IOaNoticeService 
{
    @Autowired
    private OaNoticeMapper oaNoticeMapper;

    /**
     * 查询通知公告
     * 
     * @param noticeId 通知公告主键
     * @return 通知公告
     */
    @Override
    public OaNotice selectOaNoticeByNoticeId(Long noticeId)
    {
        return oaNoticeMapper.selectOaNoticeByNoticeId(noticeId);
    }


    /**
     * 查询通知公告列表
     * 
     * @param oaNotice 通知公告
     * @return 通知公告
     */
    @Override
    public List<OaNotice> selectOaNoticeList(OaNotice oaNotice)
    {
        return oaNoticeMapper.selectOaNoticeList(oaNotice);
    }

    /**
     * 查询我的通知公告列表
     *
     * @param oaNotice 通知公告
     * @return 通知公告
     */
    @Override
    public List<OaNotice> selectMyOaNoticeList(OaNotice oaNotice)
    {
        return oaNoticeMapper.selectMyOaNoticeList(oaNotice);
    }

    /**
     * 新增通知公告
     * 
     * @param oaNotice 通知公告
     * @return 结果
     */
    @Override
    public int insertOaNotice(OaNotice oaNotice)
    {
        oaNotice.setSenderId(SecurityUtils.getUserId());
        oaNotice.setCreateTime(DateUtils.getNowDate());
        oaNotice.setCreateBy(SecurityUtils.getUsername());
        Long[] receivers = oaNotice.getReceiverIds();
        if (StringUtils.isNotNull(receivers))
        {
            StringBuilder receiver = new StringBuilder();
            for (Long receiverId: receivers)
            {
                receiver.append(receiverId);
                receiver.append(",");
            }
            oaNotice.setReceiverId(receiver.toString());
        }
        return oaNoticeMapper.insertOaNotice(oaNotice);
    }

    /**
     * 修改通知公告
     * 
     * @param oaNotice 通知公告
     * @return 结果
     */
    @Override
    public int updateOaNotice(OaNotice oaNotice)
    {
        oaNotice.setUpdateTime(DateUtils.getNowDate());
        return oaNoticeMapper.updateOaNotice(oaNotice);
    }

    /**
     * 批量删除通知公告
     * 
     * @param noticeIds 需要删除的通知公告主键
     * @return 结果
     */
    @Override
    public int deleteOaNoticeByNoticeIds(Long[] noticeIds)
    {
        return oaNoticeMapper.deleteOaNoticeByNoticeIds(noticeIds);
    }

    /**
     * 删除通知公告信息
     * 
     * @param noticeId 通知公告主键
     * @return 结果
     */
    @Override
    public int deleteOaNoticeByNoticeId(Long noticeId)
    {
        return oaNoticeMapper.deleteOaNoticeByNoticeId(noticeId);
    }
}
